<extend name="layout/edit" />

<block name="HEADER">
	<style type="text/css">
		.xw-form .layui-form{
			overflow: inherit;
		}
		.layui-form-selected .layui-edge{
			margin-top: 0 !important;
		}
		.xw-form .xw_searchs_bodys{
			line-height: 30px;padding: 10px;padding-bottom: 5px;position: relative;
		}
		.file-img {
			height: 100%;
			background-position: left;
			background-size: 100% 85%;
			background-repeat: no-repeat;
			cursor: pointer;
		}
		#selectGoodsGrid .layui-btn{ display: none; }
		.selectBtnRow{
			width: 40px;background: #f2f2f2;text-align: center;position: relative;
		}
		.selectBtnRow-boy{
			position: absolute;top: 50%;margin-top: -50px;width: 100%;
		}
		.selectBtnRow-boy div{
			padding: 5px 0;
			background: #1e9fff;
			margin-bottom: 10px;
			color: #fff;
		}
		.selectBtnRow-boy div:hover{
			color: #0000FF;
			cursor: pointer;
		}
	</style>
</block>

<block name="CONTENT">
	<div id="form" padding="" height="" style="" class="xw-form">
		<div class="wrapper" style="height: calc(100% - 42px);">
			<div class="panel-heading xw_searchs_bodys">
				<control:search id="selectUserVipSearchs" />
			</div>
			<div class="content" style="height: calc(100% - 45px);padding: 5px;display: flex;">
				<div style="width: calc(100%);">
					<control:grid id="selectUserVipGrid" padding="0" height="100%" />
				</div>
			</div>
		</div>
		<div class="xw-btnRow" style="text-align: right;">
			<button type="button" class="layui-btn layui-btn-normal layui-btn-sm " id="btnSave" onclick="page.save()" ><i class="iconfont" style="line-height: 0;"></i>确认选择</button>
			<button type="button" class="layui-btn layui-btn-normal layui-btn-sm " id="close" onclick="$.close()"> <i class="iconfont" style="line-height: 0;"></i>关闭 </button>
		</div>
	</div>

</block>

<block name="FOOTER">
	<script type="text/javascript">
		var page = (function(ns) {
			
			ns.selectedIds = [];

            ns.init = function(){

                //页面传值，选择了，就不显示。
                var filter=[{"field":"id","opera":"not in","value":$.getRequest("id")}];
                selectUserVipGrid.load(filter);


            }

            //搜索事件
            ns.query=function(){
                var filter = selectUserVipSearchs.getData();

                filter.push({"field":"id","opera":"not in","value": ns.selectedIds.join(',') });

                selectUserVipGrid.load( filter );
            }
			

			//删除
			ns.del = function(){
				var ids = $.map(selectUserVipGrid.getSelectedRows(),function(h){
					return h.id;
				});
				if(!ids[0]){
					$.toast(0,"请选择需要删除的用户");
					return false;
				}
				
				ns.selectedIds = $.map(ns.selectedIds,function(id){
					if( ids.indexOf(id) == -1 && ids.indexOf( Number(id) ) == -1 ){
						return id;
					}
				});

                selectUserVipGrid.load([{"field":"id","opera":"in","value": ns.selectedIds.join(',') }]);
				ns.query();
			}
			
			//确认事件
			ns.save = function() {

				var ids = selectUserVipGrid.getSelectedColumnValue('id');
				var datas = selectUserVipGrid.getSelectedRows();

				if(!ids){
					$.toast(0,"请先选择用户！");
					return false;
				}
				if( parent.page && parent.page.selectUserVipCallback){
					if(parent.page.selectUserVipCallback(ids,datas) !== false){
						$.close();
					}
				}else{
					$.close();
				}
			}

			return ns;
		}({}));

		$(function() { page.init(); });
	</script>
</block>